<?php

namespace home\controllers;

use home\models\Category;
use home\models\Product;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;

/**
 * Site controller
 */
class ProductController extends Controller
{

    /**
     * @return string
     */
    public function actionIndex($id)
    {
        $category = Category::findOne($id);
        $dataProvider = new ActiveDataProvider([
            'query' => Product::find()->where(['category_id' => $id, 'status' => Product::STATUS_ACTIVE])->orderBy(['id' => SORT_ASC]),
        ]);

        return $this->render('index', [
            'category' => $category,
            'data' => $dataProvider->getModels(),
            'pager' => $dataProvider->getPagination(),
        ]);
    }
}
